import type { AddressCreateDto, AddressUpdateDto, AddressListDto, AddressSingleDto } from "@/dtos/address.dto";
import type { PageRequest } from "@/types";
import http from "@/utils/http";

/**
 * 获取地址列表
 * @param params - 分页参数
 * @returns 包含地址列表、总数和总页数的对象
 */
export function getAddressListApi(params: PageRequest) {
  return http.get<any, { list: AddressListDto[]; total: number; pages: number }>("/addresses", { params });
}

/**
 * 获取单个地址
 * @param addressId - 地址ID
 * @returns 地址的详细信息
 */
export function getAddressApi(addressId: string) {
  return http.get<any, AddressSingleDto>(`/addresses/${addressId}`);
}

/**
 * 创建地址
 * @param data - 地址创建数据
 * @returns 创建成功的布尔值
 */
export function createAddressApi(data: AddressCreateDto) {
  return http.post<any, boolean>("/addresses", data);
}

/**
 * 更新地址
 * @param addressId - 地址ID
 * @param data - 地址更新数据
 * @returns 更新成功的布尔值
 */
export function updateAddressApi(addressId: string, data: AddressUpdateDto) {
  return http.put<any, boolean>(`/addresses/${addressId}`, data);
}

/**
 * 删除地址
 * @param addressId - 地址ID
 * @returns 删除成功的布尔值
 */
export function deleteAddressApi(addressId: string) {
  return http.delete<any, boolean>(`/addresses/${addressId}`);
}